# -*- coding: utf-8 -*-

import wx
import wx.grid

class GenericTable(wx.grid.PyGridTableBase):
    def __init__(self, rowLabels, colLabels, data):
        wx.grid.PyGridTableBase.__init__(self)
        self.rowLabels = rowLabels
        self.colLabels = colLabels
        self.data = data
    
    def GetNumberRows(self):
        return len(self.data)
    def GetNumberCols(self):
        return len(self.data[0])
    def GetRowLabelValue(self, row):
        if self.rowLabels:
            try:
                return self.rowLabels[row]
            except IndexError:
                return ""
    def GetColLableValue(self, col):
        if self.colLabels:
            try:
                return self.colLabels[col]
            except IndexError:
                return ""
    def IsEmptyValue(self, row, col):
        return True
    def GetValue(self, row, col):
        try:
            return self.data[row][col]
        except IndexError:
            return ""
    def SetValue(self, row, col, value):
        pass

class SimpleGrid(wx.grid.Grid):
    data = (("Tom","zhang","3","<"), ("Mark","Wang","7","5"), ("Mark","Wang"),())
    rowLabels = ("1", "2", "3","4")
    colLabels = ("A", "B", "C","D")
    def __init__(self, parent, id=-1):
        wx.grid.Grid.__init__(self, parent, id)
        subTable = GenericTable(self.rowLabels, self.colLabels, self.data)
        self.SetTable(subTable)


class Frame(wx.Frame):
    def __init__(self, parent, id=-1, title="Simple Grid"):
        wx.Frame.__init__(self, parent, id, title)
        grid = SimpleGrid(self)


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = Frame(None)
    frame.Show()
    app.MainLoop()